package com.cloudfun.campusshare.common.constant;


import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;
import java.util.Set;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/4/8 14:07
 * @description :  订单状态
 */
public enum OrderStatus {
    IN_ORDER(-1, "预约中"),
    WAIT_PAY(0, "未支付"),
    PAID(1, "已支付"),
    IN_PROGRESS(2, "进行中"),
    ALREADY_COMPLETE(3, "已完成"),
    ALREADY_CANCEL(4, "已取消"),
    TRADE_CLOSE(5, "交易关闭"),
    SUBSCRIBE_EXPIRE(6, "预约过期"),
    SELF_CLEANING(7, "筒自洁中"),
    SELF_CLEANED(8, "筒自洁完成"),
    REFUND(9, "退款"),
    ;

    /**
     * 进行中状态
     */
    public static Set<OrderStatus> PROCESSING_STATUS_SET = Sets.newHashSet(OrderStatus.SELF_CLEANING, OrderStatus.SELF_CLEANED,
            OrderStatus.IN_PROGRESS, OrderStatus.IN_ORDER, OrderStatus.PAID);

    private Integer code;
    private String message;

    OrderStatus(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static OrderStatus getOrderStatusByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        OrderStatus[] values = OrderStatus.values();
        for (OrderStatus o : values) {
            if (code.equals(o.code)) {
                return o;
            }
        }
        return null;
    }

    public static OrderStatus getOrderStatusByMsg(String message) {
        if (StringUtils.isBlank(message)) {
            return null;
        }
        OrderStatus[] values = OrderStatus.values();
        for (OrderStatus o : values) {
            if (message.equals(o.message)) {
                return o;
            }
        }
        return null;
    }
}
